]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
browser-plugin: Provide new APIs for launching extension preferences
authorJasper St. Pierre <jstpierre@mecheye.net>
Thu, 19 Jan 2012 02:30:06 +0000 (21:30 -0500)
committerJasper St. Pierre <jstpierre@mecheye.net>
Tue, 7 Feb 2012 21:00:37 +0000 (16:00 -0500)
Add two new APIs, "launchExtensionPrefs" to let SweetTooth let the user
launch the extension preferences tool directly from the browser. To allow
SweetTooth to check if an extension can be configured, add a new key to
the 'metadata', 'hasPrefs', which is returned by the GetExtensionInfo/
ListExtensions DBus methods.

https://bugzilla.gnome.org/show_bug.cgi?id=668429

browser-plugin/browser-plugin.c
js/misc/extensionUtils.js
js/ui/shellDBus.js

index d2685887efc35df011063293734ad292f89897fd..8f7e8769640c8311eed4f0c4c256f06b2092467b 100644 (file)
@@ -41,7 +41,7 @@
       "It can be used only by extensions.gnome.org"
 #define PLUGIN_MIME_STRING "application/x-gnome-shell-integration::Gnome Shell Integration Dummy Content-Type";
 
-#define PLUGIN_API_VERSION 2
+#define PLUGIN_API_VERSION 3
 
 typedef struct {
   GDBusProxy *proxy;
@@ -375,6 +375,7 @@ static NPIdentifier uninstall_extension_id;
 static NPIdentifier onextension_changed_id;
 static NPIdentifier onrestart_id;
 static NPIdentifier get_errors_id;
+static NPIdentifier launch_extension_prefs_id;
 
 static bool
 plugin_object_has_method (NPObject     *npobj,
@@ -385,7 +386,8 @@ plugin_object_has_method (NPObject     *npobj,
           name == enable_extension_id ||
           name == install_extension_id ||
           name == uninstall_extension_id ||
-          name == get_errors_id);
+          name == get_errors_id ||
+          name == launch_extension_prefs_id);
 }
 
 static inline gboolean
@@ -652,6 +654,33 @@ plugin_get_errors (PluginObject *obj,
   return jsonify_variant (res, result);
 }
 
+static gboolean
+plugin_launch_extension_prefs (PluginObject *obj,
+                               NPString      uuid,
+                               NPVariant    *result)
+{
+  gchar *uuid_str;
+
+  uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
+  if (!uuid_is_valid (uuid_str))
+    {
+      g_free (uuid_str);
+      return FALSE;
+    }
+
+  g_dbus_proxy_call (obj->proxy,
+                     "LaunchExtensionPrefs",
+                     g_variant_new ("(s)", uuid_str),
+                     G_DBUS_CALL_FLAGS_NONE,
+                     -1, /* timeout */
+                     NULL, /* cancellable */
+                     NULL, /* callback */
+                     NULL /* user_data */);
+
+  g_free (uuid_str);
+  return TRUE;
+}
+
 static int
 plugin_get_api_version (PluginObject  *obj,
                         NPVariant     *result)
@@ -762,6 +791,14 @@ plugin_object_invoke (NPObject        *npobj,
                                 NPVARIANT_TO_STRING(args[0]),
                                 result);
     }
+  else if (name == launch_extension_prefs_id)
+    {
+      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;
+
+      return plugin_launch_extension_prefs (obj,
+                                            NPVARIANT_TO_STRING(args[0]),
+                                            result);
+    }
 
   return TRUE;
 }
@@ -876,6 +913,7 @@ init_methods_and_properties (void)
   install_extension_id = funcs.getstringidentifier ("installExtension");
   uninstall_extension_id = funcs.getstringidentifier ("uninstallExtension");
   get_errors_id = funcs.getstringidentifier ("getExtensionErrors");
+  launch_extension_prefs_id = funcs.getstringidentifier ("launchExtensionPrefs");
 
   onrestart_id = funcs.getstringidentifier ("onshellrestart");
   onextension_changed_id = funcs.getstringidentifier ("onchange");
index 3ff0b22d610df6e66c5ff27641709dc499064aa9..7c2120bb571db81932402a1b18dd409d6986f2ec 100644 (file)
@@ -99,6 +99,7 @@ function loadMetadata(uuid, dir, type) {
     meta.dir = dir;
     meta.path = dir.get_path();
     meta.error = '';
+    meta.hasPrefs = dir.get_child('prefs.js').query_exists(null);
 
     return meta;
 }
index 779a173b1d8d0e0ca31ebc84bd0ff81a31498436..d3daf4b962c318b59aa679655e35be13530e1d8d 100644 (file)
@@ -3,6 +3,7 @@
 const Lang = imports.lang;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const Shell = imports.gi.Shell;
 
 const Config = imports.misc.config;
 const ExtensionSystem = imports.ui.extensionSystem;
@@ -60,6 +61,9 @@ const GnomeShellIface = <interface name="org.gnome.Shell">
     <arg type="s" direction="in" name="uuid"/>
     <arg type="b" direction="out" name="success"/>
 </method>
+<method name="LaunchExtensionPrefs">
+    <arg type="s" direction="in" name="uuid"/>
+</method>
 <property name="OverviewActive" type="b" access="readwrite" />
 <property name="ApiVersion" type="i" access="read" />
 <property name="ShellVersion" type="s" access="read" />
@@ -198,6 +202,9 @@ const GnomeShell = new Lang.Class({
             case 'number':
                 type = 'd';
                 break;
+            case 'boolean':
+                type = 'b';
+                break;
             default:
                 continue;
             }
@@ -232,6 +239,13 @@ const GnomeShell = new Lang.Class({
         return ExtensionSystem.uninstallExtensionFromUUID(uuid);
     },
 
+    LaunchExtensionPrefs: function(uuid) {
+        let appSys = Shell.AppSystem.get_default();
+        let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');
+        app.launch(global.display.get_current_time_roundtrip(),
+                   ['extension:///' + uuid], -1, null);
+    },
+
     get OverviewActive() {
         return Main.overview.visible;
     },